﻿package{
	import wck.WCK;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import wck.BodyShape;

	public class CFT extends WCK{
		
		/*public var blackMenu:MovieClip;
		public var redMenu:MovieClip;
		public var blueMenu:MovieClip;
		public var greenMenu:MovieClip;*/
		
		public function CFT(){
			myWorld.gotoAndStop(1);
			
			redMenu.cb.text = "0x0002";
			redMenu.mb.text = "0x0001";
			
			greenMenu.cb.text = "0x0002";
			greenMenu.mb.text = "0x0002";
			
			blueMenu.cb.text = "0xFFFF";
			blueMenu.mb.text = "0xFFFF";
			
			resetBtn.addEventListener(MouseEvent.CLICK, reset);
			
			setup();
		}
		private function setup():void{
			var count:int = myWorld.numChildren;
			for(var n:int = 0; n<count; n++){
				var child:BodyShape = myWorld.getChildAt(n) as BodyShape;
				if(child && child.name == "black"){
					child.type="Static";
				}
			}
			
			menuChange(blackMenu, "black");
			menuChange(redMenu, "red");
			menuChange(greenMenu, "green");
			menuChange(blueMenu, "blue");
		}
		private function reset(me:MouseEvent=null):void{
			myWorld.gotoAndStop(2);
			myWorld.gotoAndStop(1);
			setup();
		}
		private function menuChange(targ:maskMenu, color:String):void{
			apply(color, targ.cb.text, targ.mb.text, targ.gi.text);
		}
		private function apply(iName:String, cb:String, mb:String, gi:String):void{
			var count:int = myWorld.numChildren;
			for(var n:int = 0; n<count; n++){
				
				var child:BodyShape = myWorld.getChildAt(n) as BodyShape;
				if(child && child.name == iName){
					trace("iName: "+iName);
					child.groupIndex = int(gi);
					child.categoryBits = cb;
					child.maskBits = mb;
					child.awake=true;
				}
			}
		}
	}
}